package com.wzgl.core.config.plugin;

import com.jfinal.kit.PropKit;
import com.jfinal.plugin.IPlugin;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.request.UploadFileRequest;
import com.qcloud.cos.sign.Credentials;

/***
 * 腾讯云 对象存储
 * @author Administrator
 *
 */
public class COSClientPlugin implements IPlugin {
	public static COSClient cosClient = null;
	@Override
	public boolean start() {
		/***
		 * 初始化 配置文件中取出对应的 参数
		 */
		 Credentials cred = new Credentials(PropKit.getLong("AppId"),PropKit.get("SecretId"), PropKit.get("SecretKey"));
		 //生成客户的
		 ClientConfig clientConfig = new ClientConfig();
	        // 设置bucket所在的区域，比如广州(gz), 天津(tj)
	     clientConfig.setRegion("gz");
	     cosClient = new COSClient(clientConfig, cred);
		 return true;
	}

	@Override
	public boolean stop() {
		cosClient.shutdown();
		// TODO Auto-generated method stub
		return false;
	}
	/***
	 * 上传到腾讯COS
	 * @author cjy
	 * @param ur
	 * @return
	 */
	public static String cosClient(UploadFileRequest ur){
		return cosClient.uploadFile(ur);
	}
}
